<?php
/**
 * @package EXCEL
 * @copyright Авторские права (C) 2010 www.yar-it.com. Все права защищены.
 * @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
 * Price Excel! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
 * Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл copyright.php.
 */


defined( '_JEXEC' ) or die( 'Restricted access' );
error_reporting(E_ALL ^ E_NOTICE);

if (!defined( 'DS' )) {
    define( 'DS', DIRECTORY_SEPARATOR );
} 

class HTML_excel {

    function editPrice( $option, &$row, &$clist, &$originallist, &$imagelist, &$thumblist, $ad_pathoriginals, $ad_pathimages, $ad_paththumbs, $ad_thumbwidth, $ad_thumbheight, $ad_imgstyle ) {
        $user = &JFactory::getUser();
        ?>
<script type="text/javascript">
    function submitbutton(pressbutton) {
        var form = document.adminForm;
        if (pressbutton == 'cancel') {
            submitform( pressbutton );
            return;
        }
        if (form.imgtitle.value == ""){
            alert( "<?php echo _DG_PIC_ENTER_TITLE;?>" );
        } else if (form.catid.value == "0"){
            alert( "<?php echo _DG_SELECT_CAT;?>" );
        } else if (form.imgoriginalname.value == ""){
            alert( "<?php echo _DG_SELECT_ORG_PIC;?>" );
        } else if (form.imgfilename.value == ""){
            alert( "<?php echo _DG_SELECT_MED_PIC;?>" );
        } else if (form.imgthumbname.value == ""){
            alert( "<?php echo _DG_SELECT_THUMB_PIC;?>" );
        } else {
            submitform( pressbutton );
        }
    }
</script>

<table width="100%" border="0" cellspacing="0" cellpadding="6" class="adminform" style="table-layout: auto; white-space: nowrap;">
    <tr>
        <td width="50" align="left" valign="top"><form action="index2.php" method="post" name="adminForm" id="adminForm">
                <table cellpadding="4" cellspacing="1" border="0" width="100%">
                    <tr>
                        <td width="20%"><b><?php echo _DG_TITLE; ?>:</b></td>
                        <td width="80%"><input class="inputbox" type="text" name="imgtitle" size="39" maxlength="100" value="<?php echo htmlspecialchars( $row->imgtitle, ENT_QUOTES );?>" /></td>
                    </tr>
                    <tr>
                        <td valign="top"><b><?php echo _DG_CATEGORY; ?>:</b></td>
                        <td><?php echo $clist; ?> </td>
                    </tr>
                    <tr>
                        <td valign="top" align="right"><b><?php echo _DG_DESCRIPTION; ?>:</b></td>
                        <td><?php editorArea( 'editor1', str_replace('&','&amp;',$row->imgtext) , 'imgtext', '500', '200', '70', '10' ); ?>
                        </td>
                    </tr>
                    <tr>
                        <td valign="top"><b><?php echo _DG_AUTHOR_OWNER; ?>:</b></td>
                        <td><input class="inputbox" type="text" name="imgauthor" value="<?php echo $row->imgauthor; ?>" size="39" maxlength="100" />
                        </td>
                    </tr>
                </table>
                <input type="hidden" name="id" value="<?php echo $row->id; ?>" />
                <input type='hidden' name="imgoriginalname" value="<?php echo $row->imgoriginalname; ?>" />
                <input type='hidden' name="imgfilename" value="<?php echo $row->imgfilename; ?>" />
                <input type='hidden' name="imgthumbname" value="<?php echo $row->imgthumbname; ?>" />
                <input type="hidden" name="option" value="<?php echo $option;?>" />
                <input type="hidden" name="task" value="" />
                <input type="hidden" name="owner" value="<?php if ($row->owner) {
            echo $row->owner;
        } else {
            echo $user->username;
                    } ?>" />
                <input type="hidden" name="approved" value="<?php if ($row->approved == "") {
                        echo "1";
                    } else {
                        echo $row->approved;
                    } ?>" />
            </form></td>
        <td width="50" align="left" valign="top"><?php
                    $info = getimagesize(JPATH_SITE.$ad_pathoriginals."/$row->imgoriginalname");
                    $size = filesize(JPATH_SITE.$ad_pathoriginals."/$row->imgoriginalname");
                    $type = array(1=>'GIF',2=>'JPG',3=>'PNG');
                    $info[2] = $type[$info[2]];
                    $fsize = format_filesize($size);
                    $orginfo = '<table>';
                    $orginfo .= '<tr>';
                    $orginfo .= '<td>';
                    $orginfo .= _DG_ORG_WIDTH;
                    $orginfo .= '</td>';
                    $orginfo .= '<td>: ';
                    $orginfo .= $info[0].' '._DG_PIXELS;
                    $orginfo .= '</td>';
                    $orginfo .= '</tr>';
                    $orginfo .= '<tr>';
                    $orginfo .= '<td>';
                    $orginfo .= _DG_ORG_HEIGHT;
                    $orginfo .= '</td>';
                    $orginfo .= '<td>: ';
                    $orginfo .= $info[1].' '._DG_PIXELS;
                    $orginfo .= '</td>';
                    $orginfo .= '</tr>';
                    $orginfo .= '<tr>';
                    $orginfo .= '<td>';
                    $orginfo .= _DG_ORG_TYPE;
                    $orginfo .= '</td>';
                    $orginfo .= '<td>: ';
                    $orginfo .= $info[2];
                    $orginfo .= '</td>';
                    $orginfo .= '</tr>';
                    $orginfo .= '<tr>';
                    $orginfo .= '<td>';
        $orginfo .= _DG_FILESIZE;
        $orginfo .= '</td>';
        $orginfo .= '<td>: ';
        $orginfo .= $fsize;
        $orginfo .= '</td>';
        $orginfo .= '</tr>';
                                    $orginfo .= '</table>';
        ?>
            <table width="50%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td align="center"><fieldset>
                            <legend>&nbsp;<?php echo _DG_ORG_PIC_INFO; ?>&nbsp;</legend>
                            <img src="<?php echo "$ad_paththumbs/$row->imgthumbname"; ?>" style="<?php echo $ad_imgstyle; ?>" title="<?php echo _DG_THUMB_PIC_PREVIEW; ?>" /><br />
                            <br />
        <?php echo $orginfo; ?>
                        </fieldset></td>
                </tr>
            </table></td>
    </tr>
</table>
        <?php
    }

    function showPrice( $option, &$rows, &$clist, &$slist, &$search, &$pageNav ) {

        $database = &JFactory::getDBO();

        require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_excel'.DS.'class.excel.php');
        require(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_excel'.DS.'config.excel.php');
        ?>
<form action="index2.php" method="post" name="adminForm">
    <table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminheading">
        <tr>
            <th class="mediamanager"><?php echo JText::_('pex manager price'); ?></th>
        </tr>
    </table>
    <table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminlist">
        <tr>
            <th align="center">#ID</th>
            <th> <input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $rows ); ?>);" />
            </th>
            <th class="title" width="16%"><?php echo JText::_('title'); ?></th>
            <th width="18%" align="left"><?php echo JText::_('category'); ?></th>
            <th width="10%" align="left"><?php echo JText::_('pex filesize'); ?></th>
            <th width="5%" colspan="3"> <span align="center"><?php echo JText::_('order'); ?></span> <span align="center"><a href="javascript: saveorder( <?php echo count( $rows )-1; ?> )"> <img src="images/filesave.png" border="0" width="16" title="<?php echo JText::_('save order'); ?>" alt="" /></a></span> </th>
            <th width="5%"><?php echo JText::_('publish'); ?></th>
            <th width="20%" align="center"><?php echo JText::_('pex code plugin'); ?></th>
            <th width="10%"><?php echo JText::_('date'); ?></th>
        </tr>
                <?php
                JHTML::_('behavior.tooltip');
                $k = 0;
                for ($i=0, $n=count( $rows ); $i < $n; $i++) {
                    $row = &$rows[$i];
                    $task = $row->published ? 'unpublish' : 'publish';
            $img = $row->published ? 'tick.png' : 'publish_x.png';
            $database->setQuery("select id from #__users where username='$row->owner'");
            $userid = $database->loadResult();
            $size = filesize(JPATH_SITE.DS.$jx_path.DS.$row->filename);
            $type = 'XLS';
            $fsize = format_filesize($size);

            ?>
        <tr class="<?php echo "row$k"; ?>">
            <td><?php echo $row->id; ?></td>
            <td><input type="checkbox" id="cb<?php echo $i;?>" name="id[]" value="<?php echo $row->id; ?>" onclick="isChecked(this.checked);" />
            </td>
            <td><a href="javascript:editEntry(<?php echo $i; ?>); submitform('edit');"><b><?php echo $row->title; ?></b></a></td>
            <td><?php echo ShowCategoryPath($row->catid); ?></td>
            <td><?php echo $fsize; ?></td>
            <td align="center"><?php echo $pageNav->orderUpIcon( $i, ($row->catid == @$rows[$i-1]->catid) ); ?>&nbsp;&nbsp; </td>
            <td align="center"><input type="text" name="order[]" size="5" value="<?php echo $row->ordering;?>" class="text_area" style="text-align:center" /></td>
            <td align="center"><?php echo $pageNav->orderDownIcon( $i, $n, ($row->catid == @$rows[$i+1]->catid) ); ?></td>
            <td align='center'><a href="javascript: void(0);" onclick="return listItemTask('cb<?php echo $i;?>','<?php echo $task;?>')"> <img src="images/<?php echo $img;?>" width="12" height="12" border="0" alt="" /></a> </td>
            <td align="center">{excel view=xls|file=<?php echo $row->filename; ?>}</td>

            <td width="10%" align="center"><?php echo strftime("%d.%m.%Y %H:%M",$row->date); ?></td>
            <?php
            $k = 1 - $k;
            echo "</tr>";
        }
        ?>
            <th align="center" colspan="13"> <?php echo $pageNav->getListFooter(); ?></th>
        </tr>
    </table>
    <input type="hidden" name="option" value="<?php echo $option;?>" />
    <input type="hidden" name="task" value="" />
    <input type="hidden" name="boxchecked" value="0" />
</form>
        <?php
    }


    function showCats( &$rows, $search, $pageNav, $option ) {
        ?>
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
<script type="text/javascript" src="../includes/js/overlib_mini.js"></script>
<form action="index2.php" method="post" name="adminForm">
    <table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminheading">
        <tr>
            <th class="categories"><?php echo JText::_('categories'); ?></th>
            <td><?php echo JText::_('search'); ?>:</td>
            <td><input type="text" name="search" value="<?php echo $search;?>" class="inputbox" onchange="document.adminForm.submit();" />
            </td>
        </tr>
        <tr>
            <td width="100%"></td>
        </tr>
    </table>
    <table width="100%" border="0" cellpadding="4" cellspacing="0"  class="adminlist">
        <tr>
            <th width="20">#ID</th>
            <th width="20"> <input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $rows ); ?>);" />      </th>
            <th class="title" nowrap="nowrap"><?php echo JText::_('category'); ?></th>
            <th align="left"><?php echo JText::_('description'); ?></th>
            <th nowrap="nowrap"><?php echo JText::_('pex files_on'); ?></th>
            <th nowrap="nowrap"><?php echo JText::_('publish'); ?></th>
            <th nowrap="nowrap"><?php echo JText::_('access'); ?></th>
            <th colspan="3" nowrap="nowrap"> <span align="center"><?php echo JText::_('order'); ?></span> <span align="center"><a href="javascript: saveorder( <?php echo count( $rows )-1; ?> )"> <img src="images/filesave.png" border="0" width="16" title="<?php echo JText::_('save order'); ?>" alt="" /></a></span></th>
        </tr>
        <?php
        JHTML::_('behavior.tooltip');
        $k = 0;
        $i = 0;
        for ($i=0, $n=count( $rows ); $i < $n; $i++) {
                        $row = &$rows[$i];
                        ?>
        <tr class="row<?php echo $k; ?>">
            <td align="center"><?php echo $row->cid; ?></td>
            <td width="20"><input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $row->cid; ?>" onclick="isChecked(this.checked);">      </td>
            <td align="left" width="25%"><a href="#edit" onclick="return listItemTask('cb<?php echo $i; ?>','editcat')"><?php echo $row->name; ?></a></td>
            <td align="left" width="55%"><?php echo $row->descript; ?></td>
            <td align="center" width="5%"><?php echo GetNumberOfLinks ($row->cid);?></td>
                                <?php
            $task = $row->published ? 'unpublishcat' : 'publishcat';
            $img = $row->published ? 'tick.png' : 'publish_x.png';
            ?>
            <td width="10%" align="center" nowrap="nowrap"><a href="javascript: void(0);" onclick="return listItemTask('cb<?php echo $i;?>','<?php echo $task;?>')"><img src="images/<?php echo $img;?>" width="12" height="12" border="0" alt="" /></a></td>
            <td width="10%" align="center" nowrap="nowrap"><?php echo $row->groupname;?></td>
            <td><?php if ($i > 0 || ($i+$pageNav->limitstart > 0)) { ?>
                <div align="center"><a href="#reorder" onclick="return listItemTask('cb<?php echo $i;?>','orderupcat')"> <img src="images/uparrow.png" width="12" height="12" border="0" title="<?php JText::_('move up'); ?>"></a>
                <?php } else {
                echo "&nbsp;";
            } ?>
                </div></td>
            <td><input type="text" name="order[]" size="5" value="<?php echo $row->ordering;?>" class="text_area" style="text-align:center" /></td>
            <td><?php if ($i < $n-1 || $i+$pageNav->limitstart < $pageNav->total-1) { ?>
                <div align="center"><a href="#reorder" onclick="return listItemTask('cb<?php echo $i;?>','orderdowncat')"> <img src="images/downarrow.png" width="12" height="12" border="0" title="<?php echo JText::_('move down'); ?>"></a>
                <?php } else {
                echo "&nbsp;";
            } ?>
                </div></td>
            <?php $k = 1 - $k;
        } ?>
        </tr>
        <tr>
            <th align="center" colspan="10"> <?php echo $pageNav->getListFooter(); ?></th>
        </tr>
    </table>
    <input type="hidden" name="option" value="<?php echo $option; ?>">
    <input type="hidden" name="task" value="showcat">
    <input type="hidden" name="boxchecked" value="0">
</form>
        <?php
    }
    function editCats( &$row, &$publist, $option , $glist , $Lists, $orderlist ) {

        global $mainframe;
        jimport('joomla.filter.output');
        $quote_style = ENT_QUOTES;
        JFilterOutput::objectHTMLSafe( $row, $quote_style, 'descript' );
        ?>
<script type="text/javascript">
    function submitbutton(pressbutton) {
        var form = document.adminForm;
        if (pressbutton == 'cancelcat') {
            submitform( pressbutton );
            return;
        }

        try {
            document.adminForm.onsubmit();
        }
        catch(e){}
        if (form.name.value == ""){
            alert( "<?php echo JText::_('pex titles'); ?>" );
        } else {
            submitform( pressbutton );
        }
    }
</script>
<table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminheading">
    <tr>
        <th class="categories"><?php echo $row->cid ? JText::_('edit category') : JText::_('add'); ?></th>
    </tr>
</table>
<form action="index2.php" method="post" name="adminForm">
    <table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminform">
        <tr>
            <td width="200"><b><?php echo JText::_('title'); ?>:</b></td>
            <td><input class="inputbox" type="text" name="name" size="25" value="<?php echo $row->name; ?>">
            </td>
        </tr>
        <tr>
            <td valign="top"><b><?php echo JText::_('description'); ?>:</b></td>
            <td><textarea name="descript" id="descript" cols="70" rows="3"><?php echo $row->descript; ?></textarea>
            </td>
        </tr>
        <tr>
            <td valign="top" ><b><?php echo JText::_('access'); ?>:</b></td>
            <td nowrap ><?php echo $glist?></td>
        </tr>
        <tr>
            <td valign="top" ><b><?php echo JText::_('order'); ?>:</b></td>
            <td nowrap ><?php echo $orderlist?></td>
        </tr>
        <tr>
            <td valign="top" ><b><?php echo JText::_('publish'); ?>:</b></td>
            <td nowrap ><?php echo $publist?></td>
        </tr>
    </table>
</div>
<input type="hidden" name="cid" value="<?php echo $row->cid; ?>">
<input type="hidden" name="task" value="">
<input type="hidden" name="option" value="<?php echo $option; ?>">
</form>
        <?php
    }
}

?>
